<?php
include("../common.inc.php");
InitGP(array("page","action","did","delids")); //初始化變量全局返回
include("function_common.php");
//初始化對象
include(INC_PATH."/delivery.class.php");
$dl=new DeliveryClass();


if(empty($action)){
	InitGP(array("name")); //初始化變量全局返回
	if(!empty($uname))$wherestr[]="name like '%{$name}%'";
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//條件匯總
	
	//獲取當前頁碼
	$total=$dl->getcount($wheresql); 							  //總信息數
	$pagesize=15;												  //一頁顯示信息數
	$page = isset($page) ? max(1, intval($page)) : 1;             //處理頁碼變量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$dl->getdata("$offset,$pagesize",$wheresql); //獲取數據
	
	//包含後台模板文件
	include("tpl/pay_delivery.htm");
}elseif ($action=="update") {
	//更新狀態禁用或者啟用
	
	InitGP(array("did")); //初始化變量全局返回
	//$state=$dl->state($did)?0:1;
	//$dl->state($did,$state);
	//showmsg("設置狀態成功!","pay_delivery.php");//成功
}elseif ($action=="edit") {
	InitGP(array("did","name","first_weight","continue_weight","first_fee","continue_fee","about","Submit")); //初始化變量全局返回
	if(!empty($Submit)){
		$addarray=array(
			"name"=>$name,
			"first_weight"=>$first_weight,
			"continue_weight"=>$continue_weight,
			"first_fee"=>$first_fee,
			"continue_fee"=>$continue_fee,
			"about"=>$about
		);
	
		$info=$dl->edit($did,$addarray);
		if($info=="OK"){showmsg("編輯成功!","pay_delivery.php");//成功
		}else showmsg($info,"-1");//出錯！	

	
	
	
	}else {
	
	//編輯信息表單
	$dataedit=$dl->getdata(1,"did={$did}");
	$value=$dataedit[0];//獲取第一條記錄
	//包含後台模板文件
	include("tpl/pay_delivery.htm");	
	}
	
}elseif ($action=="add") {	
	InitGP(array("name","first_weight","continue_weight","first_fee","continue_fee","about","Submitadd")); //初始化變量全局返回
	if(!empty($Submitadd)){
		$addarray=array(
			"name"=>$name,
			"first_weight"=>$first_weight,
			"continue_weight"=>$continue_weight,
			"first_fee"=>$first_fee,
			"continue_fee"=>$continue_fee,
			"about"=>$about
		);
	
		$info=$dl->add($addarray);
		if($info=="OK"){showmsg("添加成功!","pay_delivery.php");//成功
		}else showmsg($info,"-1");//出錯！	

	}else {
		include("tpl/pay_delivery.htm");	
	}
	
}elseif ($action=="del" && !empty($did)){
	//執行刪除操作
	$did=GetNum($did);
	$info=$dl->del($did);
	if($info=="OK")showmsg("刪除成功！","pay_delivery.php");
	else showmsg($info,"pay_delivery.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("沒有選擇任何對象！","pay_delivery.php");exit;}//空選擇
	//執行刪除多個操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$dl->del($id);
	}
	if($info=="OK")showmsg("刪除用戶成功！","pay_delivery.php");
	else showmsg($info,"pay_delivery.php");
}

?>

